package com.chance.cc.crawler.development.command.trigger.domain.bilibili;

import com.chance.cc.crawler.core.downloader.HttpPage;
import com.chance.cc.crawler.development.command.job.domain.bilibili.realtime.BilibiliNormalCrawlerJob;
import com.chance.cc.crawler.development.command.job.domain.bilibili.trace.BilibiliTraceCrawlerJob;
import com.chance.cc.crawler.development.command.trigger.CrawlerJobTriggerCommand;
import com.chance.cc.crawler.meta.core.bean.CrawlerMetaConstant;

/**
 * @author lt
 * @version 1.0
 * @date 2021-02-02 18:06:06
 * @email okprog@sina.com
 */
public class BilibiliSchedulerTrigger {
    private static final String domain = "bilibili";

    private static final CrawlerJobTriggerCommand crawlerJobTriggerCommand =
            new CrawlerJobTriggerCommand("192.168.1.215",9599);

    public static void main(String[] args) {

        publishBilibiliNormalCrawlerScheduleTriggerInfo(BilibiliNormalCrawlerJob.bitAutoScheduler().generateCrawlerKey(),BilibiliNormalCrawlerJob.bitAutoScheduler().generateCrawlerTriggerKey());

        publishBilibiliTraceCrawlerScheduleTriggerInfo(BilibiliTraceCrawlerJob.bilibiliScheduler().generateCrawlerKey(),BilibiliTraceCrawlerJob.bilibiliScheduler().generateCrawlerTriggerKey());

    }


    /**
     * 发布bilibili视频trigger info
     * @param crawlerKey
     * @param crawlerTriggerKey
     */
    public static void publishBilibiliNormalCrawlerScheduleTriggerInfo(String crawlerKey,String crawlerTriggerKey){
        HttpPage httpPage = crawlerJobTriggerCommand.addOrUpdateScheduleCrawlerTrigger(
                crawlerKey,
                crawlerTriggerKey,
                domain,
                CrawlerMetaConstant.ScheduleJobTrigger_Cron,
                "0 0/30 * * * ?",
                "bilibili视频实时采集任务，每三十分钟执行一次"
        );
        System.out.println("添加采集调度信息：" + httpPage.getRawText());
        System.out.println("triggerKey: " + crawlerTriggerKey);
    }
    /**
     * 发布bilibili视频回溯trigger info
     * @param crawlerKey
     * @param crawlerTriggerKey
     */
    public static void publishBilibiliTraceCrawlerScheduleTriggerInfo(String crawlerKey,String crawlerTriggerKey){
        HttpPage httpPage = crawlerJobTriggerCommand.addOrUpdateScheduleCrawlerTrigger(
                crawlerKey,
                crawlerTriggerKey,
                domain,
                CrawlerMetaConstant.ScheduleJobTrigger_Cron,
                "0 0 0 * * ?",
                "bilibili视频回溯7天采集前一天回复任务，每天0点执行一次"
        );
        System.out.println("添加采集调度信息：" + httpPage.getRawText());
        System.out.println("triggerKey: " + crawlerTriggerKey);
    }

    /**
     * 发布bilibili视频回溯trigger info
     * @param crawlerKey
     * @param crawlerTriggerKey
     */
    public static void publishBilibiliCommentTraceCrawlerScheduleTriggerInfo(String crawlerKey,String crawlerTriggerKey){
        HttpPage httpPage = crawlerJobTriggerCommand.addOrUpdateScheduleCrawlerTrigger(
                crawlerKey,
                crawlerTriggerKey,
                domain,
                CrawlerMetaConstant.ScheduleJobTrigger_Cron,
                "0 0 * * * ?",
                "bilibili视频回溯回复任务，每小时执行一次"
        );
        System.out.println("添加采集调度信息：" + httpPage.getRawText());
        System.out.println("triggerKey: " + crawlerTriggerKey);
    }

}
